$(function () {
    //加载地区对应的疫情情况
    loadData("香港");
    //加载下拉框
    loadProvinceName("provinceName");
})

//加载下拉框
function loadProvinceName(id) {
    //发送请求获取数据
    $.ajax({
        url:"../info/queryAllProvinceName",
        dataType:"json",
        type:"post",
        success:function (data) {
            var str="";
            for (var i = 0; i < data.length; i++) {
                str+="<option>"+data[i]+"</option>>"
            }
            $("#provinceName").html(str);
            $("#confirmArea").html(str);
            $("#curedArea").html(str);
            $("#deadArea").html(str);
        },error:function () {
            layer.alert("服务器错误");
        }
    })
}

//加载饼图数据
function loadData(name) {
    var pie_five = echarts.init(document.getElementById("pie_yiqing"), 'infographic');
    $.ajax({
        url:"../info/queryEpidemicByProvinceName",
        type:"post",
        dataType: "json",
        data:{"provinceName":name},
        success:function (data) {
            option = {
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: ['现有确诊','现有治愈','现有死亡'],
                    textStyle: {color: 'balck'}
                },
                series: [
                    {
                        name: '各省疫情分析',
                        type: 'pie',
                        radius: '50%',
                        data:data,
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            pie_five.setOption(option);
        },error:function () {
            layer.alert("服务处错误");
        }
    })

}

//下拉框改变函数
function selectByName() {
    var provinceName=$("#provinceName").val();
    loadData(provinceName);
}
